package com.pox.guli.service.vod.controller.api;

import com.pox.guli.common.base.result.R;
import com.pox.guli.common.base.result.ResultCodeEnum;
import com.pox.guli.common.base.util.ExceptionUtils;
import com.pox.guli.service.base.exception.PoXException;
import com.pox.guli.service.vod.service.VodVideoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @Author PoX21s
 * @Date: 2022/1/5 13:58
 * @Version 1.0
 */

@Api(description="阿里云视频点播")
//@CrossOrigin
@RestController
@RequestMapping("/api/vod/media")
@Slf4j
public class ApiMediaController {

    @Resource
    private VodVideoService vodVideoService;

    @GetMapping("/get-play-auth/{videoSourceId}")
    public R getPlayAuth(@ApiParam(value = "阿里云视频文件的id", required = true)
                         @PathVariable String videoSourceId){

        try{
            String playAuth = vodVideoService.getPlayAuth(videoSourceId);

            return  R.ok().message("获取播放凭证成功").data("playAuth", playAuth);
        } catch (Exception e) {
            log.error(ExceptionUtils.getMessage(e));
            throw new PoXException(ResultCodeEnum.FETCH_PLAYAUTH_ERROR);
        }
    }
}